<?php

namespace app\api\controller;

use app\common\controller\Base;

/**
 * 仪事接口
 */
class Backlog extends Base
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];


    //发仪事初始数据
    public function pre()
    {
        $data['user'] = \app\common\model\User::getUserLists();
        $this->success('ok', $data);
    }

    //列表
    public function index()
    {
        $params = $this->request->get();
        $this->success('仪事列表',\app\common\model\Backlog::getLists($params));
    }

    //详情
    public function detail()
    {
        $id = $this->request->get('id');
        if (!$id){
            $this->error(__('Invalid parameters'));
        }
        $row = \app\common\model\Backlog::get($id);
        if (!$row){
            $this->error(__('No Results were found'),['row'=>$row]);
        }
        $this->success('详情',['row'=>$row]);
    }

    //编辑
    public function edit()
    {
        $params = $this->request->post();
        $this->apiValidate($params,\app\api\validate\Backlog::class, 'edit');
        $this->success('操作成功',\app\common\model\Backlog::operEdit($params));
    }

    //删除
    public function del()
    {
        $id = $this->request->post('id');
        if (!$id){
            $this->error(__('Invalid parameters'));
        }
        $this->success('操作成功',\app\common\model\Backlog::operDel($id));
    }

    //完成
    public function finish()
    {
        $params = $this->request->post();
        $this->apiValidate($params,\app\api\validate\Backlog::class, 'finish');
        $this->success('操作成功',\app\common\model\Backlog::operFinish($params));
    }

}
